﻿/*
*┌────────────────────────────────────────────────┐
*│　描    述：WDPushBusiness                                                   
*│　作    者： (Jxw)                                             
*│　版    本：1.0     
*│　功能描述：                                          
*│　创建时间：2021/4/20 10:57:34                        
*└────────────────────────────────────────────────┘
*/

using Data;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Utility;

namespace Business
{
    public class WDPushBusiness
    {
        private static WDPushBusiness m_PushBusiness = null;
        private DataChangeLog m_DataChangeLog = new DataChangeLog(); //数据变化日志数据访问

        private WDPushBusiness()
        {

        }

        public static WDPushBusiness PushBusiness
        {
            get
            {
                if (m_PushBusiness == null)
                    m_PushBusiness = new WDPushBusiness();
                return m_PushBusiness;
            }
        }

        public void pushPatientResuorceData(DataView dv)
        {
            try
            {
                
                for (int i = 0; i < dv.Count; i++)
                {
                    string strDataChangePKCode = Convert.ToString(dv[i]["编码"]);
                    string strOperate = dv[i]["操作"] as string;
                    string strPKCode = dv[i]["主键"] as string;
                    EventUtility.OnShowMsg("开始获取院前调度急救数据（120专线） 主键：" + strPKCode, false);
                    string data = PatientResuorce.patientResuorce.GetDisPatientInfo(strPKCode);

                    if (!string.IsNullOrEmpty(data))
                    {
                        if (strOperate.Equals("新增") || strOperate.Equals("修改"))
                        {
                            EventUtility.OnShowMsg("推送院前调度急救数据（120专线）", false);

                            string ptResult = HttpService.PostResponse(AppConfig.DDJJUrl, data, AppConfig.appCode, AppConfig.sign);
                            RetDTO ret = JsonHelper.DeserializeObject<RetDTO>(ptResult);
                            if (ret.ack.code == "0")
                            {
                                m_DataChangeLog.UpdateDataChangeSign(strDataChangePKCode);
                                EventUtility.OnShowMsg("推送调度急救数据（120专线）成功！ 操作:" + strOperate, false);
                                LogUtility.Debug("WDPushBusiness/pushPatientResuorceData", "推送调度急救数据（120专线）成功" + ret);
                            }
                            else
                            {
                                EventUtility.OnShowMsg("推送调度急救数据（120专线）失败，请查看日志", true);
                                LogUtility.Debug("WDPushBusiness/pushPatientResuorceData", "状态码：" + ret.ack.code + ",   " + ret.ack.text);
                            }
                        }
                    }
                    else
                    {
                        m_DataChangeLog.UpdateDataChangeSign(strDataChangePKCode);
                    }
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                LogUtility.Error("WDPushBusiness/pushPatientResuorceData", "推送调度急救数据（120专线）失败：" + ex.ToString());
            }
         

        }


        /// <summary>
        /// 到达医院推送数据
        /// </summary>
        /// <param name="taskCode"></param>
        public void pushPatientResuorceData(TToldInfo toldInfo)
        {
            try
            {
                string data = PatientResuorce.patientResuorce.GetDisPatientInfo(toldInfo.toldCode);

                if (!string.IsNullOrEmpty(data))
                {
                    string ptResult = HttpService.PostResponse(AppConfig.DDJJUrl, data, AppConfig.appCode, AppConfig.sign);
                    RetDTO ret = JsonHelper.DeserializeObject<RetDTO>(ptResult);
                    if (ret.ack.code == "0")
                    {
                        EventUtility.OnShowMsg("推送到达医院的告知调度信息成功", false);
                        LogUtility.Debug("WDPushBusiness/pushPatientResuorceData", "推送到达医院告知调度急救数据成功" + ret);
                    }
                    else
                    {
                        EventUtility.OnShowMsg("推送到达医院的告知调度急救数据失败，请查看日志", true);
                        LogUtility.Debug("WDPushBusiness/pushPatientResuorceData", "状态码：" + ret.ack.code + ",   " + ret.ack.text);
                    }
                }

            }
            catch (Exception ex)
            {
                LogUtility.Error("WDPushBusiness/pushPatientResuorceData", "推送到达医院的告知调度急救数据失败：" + ex.ToString());
            }
        }

    }
}
